﻿
Partial Class WebForm_ManageMOIExport_OrganizationControl
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            'Me.BindGV()
        End If
    End Sub

    Public Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.Length = 0

        'sql.AppendFormat(" Select distinct father.OrganizationName AS FatherName,son.OrganizationName,'C14' AS DomainType, ")
        'sql.AppendFormat(" 'F' AS CityType,A.MOIValue AS OrgType,B.MOIValue AS IsGovernment,'0' AS JoinPlan, ")
        'sql.AppendFormat(" son.Phone,'' AS Fax,son.RegionNO AS RegionNum,son.CityNO AS CityCode,r.RegionName+son.Address AS OrgAddress,  ")
        'sql.AppendFormat(" son.Introduction AS OrgIntroduction, ")
        'sql.AppendFormat("right('00'+CAST((YEAR(son.EstablishDate)-1911) AS VARCHAR)+RIGHT(CONVERT(VARCHAR(12),son.EstablishDate,111),6),9) as EstablishDate")
        'sql.AppendFormat(",'' AS OrgNO ")
        'sql.AppendFormat(" From OrganizationView son Left Join Organization father ON son.Parent = father.OrganizationID ")
        'sql.AppendFormat(" Left Join CodeMapping A ON son.MOIOrganizationType=A.Value And A.tableName='Organization' And A.ColumnName='MOIOrganizationType' ")
        'sql.AppendFormat(" Left Join CodeMapping B ON son.IsGov = B.Value And B.tableName='Organization' And B.ColumnName='IsGov' ")
        'sql.AppendFormat(" Left Join Region r ON son.RegionNO = r.RegionID ")
        'sql.AppendFormat(" Where 1=1 ")


        'sql.AppendFormat(" And son.UOrganizationID = '{0}' ", Me.OrgID)
        'sql.AppendFormat(" UNION ALL ")
        sql.AppendFormat(" Select distinct son.OrganizationName,'C14' AS DomainType, ")
        sql.AppendFormat(" 'F' AS CityType,A.MOIValue AS OrgType,B.MOIValue AS IsGovernment,'N' AS JoinPlan, ")
        sql.AppendFormat(" case when son.Phone<>'' then son.Phone else '02-29603456' end as Phone,'' AS Fax,case when son.RegionNO<>'' then son.RegionNO else '220' end AS RegionNum,case when son.CityNO<>'' then son.CityNO else 'F' end AS CityCode,case when son.Address<>'' then r.RegionName+son.Address else son.OrganizationName end AS OrgAddress,  ")
        sql.AppendFormat(" case when son.Introduction<>'' then son.Introduction else son.OrganizationName end AS OrgIntroduction, ")
        sql.AppendFormat("case when son.EstablishDate<>'' then right('0'+CAST((YEAR(son.EstablishDate)-1911) AS VARCHAR)+RIGHT(CONVERT(VARCHAR(12),son.EstablishDate,112),4),7)  else '0900120' end as EstablishDate,'' AS OrgNO ")

        sql.AppendFormat(" From OrganizationView father Inner Join OrganizationView son ON father.OrganizationID = son.Parent ")
        sql.AppendFormat(" Left Join CodeMapping A ON son.MOIOrganizationType=A.Value And A.tableName='Organization' And A.ColumnName='MOIOrganizationType' ")
        sql.AppendFormat(" Left Join CodeMapping B ON son.IsGov = B.Value And B.tableName='Organization' And B.ColumnName='IsGov' ")
        sql.AppendFormat(" Left Join Region r ON son.RegionNO = r.RegionID ")
        sql.AppendFormat(" Where 1=1 and father.Active='Y' and son.Active='Y' ")
        If Me.OrgID <> "" Then
            sql.AppendFormat(" And father.UOrganizationID = '{0}' ", Me.OrgID)
        End If
        OrganizationDT = dat.GetData(sql)

        Me.gv.DataSource = OrganizationDT
        Me.gv.DataBind()

    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub

    'Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
    '    If e.Row.RowType = DataControlRowType.DataRow Then

    '        If CType(e.Row.FindControl("lblEstablishDate"), Label).Text <> "" Then
    '            Dim d() As String = CType(e.Row.FindControl("lblEstablishDate"), Label).Text.Split(".")     'year=d(0),month=d(1),day=d(2)

    '            '日期格式 099/01/01
    '            If d(0).Length = 2 Then
    '                d(0) = "0" + d(0)
    '            End If

    '            If d(1).Length = 1 Then
    '                d(1) = "0" + d(1)
    '            End If

    '            If d(2).Length = 1 Then
    '                d(2) = "0" + d(2)
    '            End If

    '            CType(e.Row.FindControl("lblEstablishDate"), Label).Text = d(0) + "/" + d(1) + "/" + d(2)
    '        End If



    '    End If
    'End Sub

    Public Property OrganizationDT() As Data.DataTable
        Get
            Return ViewState("OrganizationDT")
        End Get
        Set(ByVal value As Data.DataTable)
            ViewState("OrganizationDT") = value
        End Set
    End Property
    Public Property OrgID() As String
        Get
            Return ViewState("OrgID")
        End Get
        Set(ByVal value As String)
            ViewState("OrgID") = value
        End Set
    End Property
End Class
